package com.example.ex2

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.ex2.ui.theme.Ex2Theme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
            Ex2Theme {
                Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
                    Greeting(
                        name = "杨谨键",
                        modifier = Modifier.padding(innerPadding)
                    )
                }
            }
        }
    }
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
    val img = painterResource(R.drawable._a)
    val img1 = painterResource(android.R.drawable.ic_menu_call)
    val img2 = painterResource(android.R.drawable.presence_away)
    val img3 = painterResource(android.R.drawable.ic_dialog_email)

    Column(
        verticalArrangement = Arrangement.Center,
        horizontalAlignment = Alignment.CenterHorizontally,
        modifier = modifier.fillMaxSize()
    )  {

        Spacer(modifier = Modifier.height(200.dp))

        Column(
            verticalArrangement = Arrangement.Center,
            horizontalAlignment = Alignment.CenterHorizontally,
            modifier = modifier.fillMaxWidth().weight(1f, false)
        ) {
            Image(
                painter = img,
                contentDescription = null,
                alpha = 1F,
                modifier = Modifier.padding(vertical = 10.dp)
            )
            Text(
                text = "你好 $name!",
                textAlign = TextAlign.Center,
                fontSize = 15.sp,
                lineHeight = 15.sp,
                modifier = Modifier.padding(vertical = 1.dp)
            )
            Text(
                text = "计算机2302",
                fontSize = 15.sp,
                lineHeight = 15.sp,
                modifier = Modifier.padding(vertical = 1.dp)
            )
        }

        Spacer(modifier = Modifier.height(100.dp))
        Column(verticalArrangement = Arrangement.Center,
            horizontalAlignment = Alignment.CenterHorizontally,
            modifier = modifier.fillMaxWidth().weight(1f, false)) {
            Row(horizontalArrangement = Arrangement.Center,
                verticalAlignment = Alignment.CenterVertically,
                modifier = Modifier.padding(vertical = 5.dp)) {
                Icon(
                    painter = img1,
                    contentDescription = null,
                    modifier = Modifier
                        .height(30.dp)
                        .width(30.dp)
                )
                Text(
                    text = "13881814060",
                    textAlign = TextAlign.Center,
                    fontSize = 20.sp,
                    lineHeight = 20.sp,
                    modifier = Modifier)
            }
            Row(horizontalArrangement = Arrangement.Center,
                verticalAlignment = Alignment.CenterVertically,
                modifier = Modifier.padding(vertical = 5.dp)) {
                Icon(
                    painter = img2,
                    contentDescription = null,
                    modifier = Modifier
                        .height(30.dp)
                        .width(30.dp))
                Text(
                    text = "QQ：2094260855",
                    textAlign = TextAlign.Center,
                    fontSize = 20.sp,
                    lineHeight = 20.sp,
                    modifier = Modifier)
            }
            Row(horizontalArrangement = Arrangement.Center,
                verticalAlignment = Alignment.CenterVertically,
                modifier = Modifier.padding(vertical = 5.dp)) {
                Icon(
                    painter = img3,
                    contentDescription = null,
                    modifier = Modifier
                        .height(30.dp)
                        .width(30.dp))
                Text(
                    text = "2094260855@qq.com",
                    textAlign = TextAlign.Center,
                    fontSize = 20.sp,
                    lineHeight = 20.sp,
                    modifier = Modifier)
            }
        }
    }
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
    Ex2Theme {
        Greeting("杨谨键")
    }
}